<template>
  <div class="org-search">
    <SearchItem  v-for="(item, index) in pageData" :key="index" :info=item />     
    <a-pagination show-quick-jumper :default-current="1" :defaultPageSize="5" :pageSize=pageSize :current=pageNum :total=totalCount @change="onChange" v-if="totalCount > 0"/>
    <h3 style="color:#888" v-if="totalCount <= 0">---- 暂无数据 ----</h3>
  </div>
</template>
<script lang="ts">

import { defineComponent,PropType,ref, reactive ,watchEffect,watch,onMounted} from "vue";
import { useRoute,onBeforeRouteUpdate } from "vue-router"
import  SearchItem  from "@/components/SearchItem.vue"
import { post,get } from '../../net/netMethod.js';

export default defineComponent({
  components:{
    SearchItem,
  },
  props: {
    pageData: {
      type: Array,
      default: () => [],
    },
    total:{
      type: Number,
      default: 1,
    }
  },
  setup: (props, context) => {
   const router = useRoute();
    console.log(router);
    var thisInfo= []
    var  pageNum = 1;
    var  pageSize=5;
    var  totalCount=0;
    var  totalPage=2;

    const onChange = (page, size)=>{
       pageNum = page;
       pageSize = size;

      var url = router.query.url as string;
      post(this,url,{
        pageNum:pageNum,
        pageSize:pageSize
      }).then(result => {
         defaultData.pageData = result.resultData.pageData;
         defaultData.pageNum = result.resultData.pageNum
         defaultData.totalCount = result.resultData.totalCount
         defaultData.pageSize = result.resultData.pageSize
         console.log(defaultData, "=====");
      })
    }

    const defaultData = reactive({
      pageData: thisInfo,
      total:1,
      pageNum,
      totalCount,
      pageSize,
      onChange
    });
    onMounted(() => {    
      console.log(router.query.id)
      var data = router.params.resultData as string;
      var url = router.query.url as string;
      post(this,url,{
        pageNum:pageNum,
        pageSize:pageSize
      }).then(result => {
         defaultData.pageData = result.resultData.pageData;
         defaultData.pageNum = result.resultData.pageNum
         defaultData.totalCount = result.resultData.totalCount
         defaultData.pageSize = result.resultData.pageSize

      })
   
    })

     
    onBeforeRouteUpdate((to,from,next) => {
      
      var url = to.query.url as string;
      post(this,url,{
        pageNum:pageNum,
        pageSize:pageSize
      }).then(result => {
         defaultData.pageData = result.resultData.pageData;
         defaultData.pageNum = result.resultData.pageNum
         defaultData.totalCount = result.resultData.totalCount
         defaultData.pageSize = result.resultData.pageSize
         console.log(defaultData, "=====");
      })
      
    });

   
    watch(() => defaultData, (count, prevCount) => { 
      console.log(count, prevCount) 
    }) 

    return defaultData;
  }
})
</script>

<style lang="less" scoped>

.org-search{
  margin-top: 25px;
}

</style>